from Tkinter import *
import listboxWrapper


class SelectionFrame(Frame):

    def __init__(self, master, inputReceivingMethod, colors):
        Frame.__init__(self, master)
        self.master = master
        self.inputReceivingMethod = inputReceivingMethod
        self.frame1 = Frame(master, background=colors[0])
        self.frame2 = Frame(master, background=colors[1])
        self.opptionsFrame =  listboxWrapper.ListboxWrapper(self.frame1, \
                                                            colors[0], 6)
        self.chosenFrame = listboxWrapper.ListboxWrapper(self.frame2, \
                                                         colors[1], 4)
        self.chooseButton = Button(master, background=colors[2], \
                                   text="Choose", width=8, height=2)
        self.addButton = Button(master, background=colors[2], \
                                        text="Add", width=8)
            
        self.frame1.grid(row=3, column=0, rowspan=6, columnspan=6,padx=10, \
                         pady=10)   
        self.frame2.grid(row=12, column=0, rowspan=6, columnspan =6)
        self.chooseButton.grid(row=4, column=7, rowspan=2, sticky=W+N+S+E)
        self.addButton.grid(row=2, column=7, rowspan=2, sticky=W+E)
       
        self.addButton.config(command=self.add)
        self.chooseButton.config(command=self.choose)
      

    def add(self):
        item = self.inputReceivingMethod(self.master)
        if (item != None):
            self.opptionsFrame.addItems([item])
      
    def choose(self):
        self.opptionsFrame.saveCurrentSelection()
        selection = self.opptionsFrame.getSelection()
        self.chosenFrame.addItems(selection)

    def getChoice(self):
        return self.chosenFrame.getAllItems()
    
    